package com.myChat;

import java.io.IOException;
import java.net.*;

public class MyReceiver {
    public static void main(String[] args) {
        DatagramSocket ds = null;
        while (true) {
            try {
                InetAddress ip = InetAddress.getByName("192.168.254.101");
                ds = new DatagramSocket(8001, ip);
                byte[] buffer = new byte[1024];
                DatagramPacket dp = new DatagramPacket(buffer, buffer.length);
                ds.receive(dp);
                String rMsg = new String(buffer, 0, dp.getLength());
                System.out.println("服务端说：" + rMsg);
            } catch (UnknownHostException e) {
                e.printStackTrace();
            } catch (SocketException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (ds != null) {
                    ds.close();
                }
            }
        }
    }
}

